home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / ccmd / ccmd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-19  |  7.5 KB  |  207 lines

  1. /*
  2.  Author: Andrew Lowry
  3.  
  4.  Columbia University Center for Computing Activities, July 1986.
  5.  Copyright (C) 1986, 1987, Trustees of Columbia University in the City
  6.  of New York.  Permission is granted to any individual or institution
  7.  to use, copy, or redistribute this software so long as it is not sold
  8.  for profit, provided this copyright notice is retained.
  9. */
  10.  
  11. /* ccmd.h
  12.  *
  13.  * Include this file if your program will make use of the CCMD
  14.  * command parsing routines.  Included here are function and
  15.  * flag definitions, error codes, and parsing structure declarations.
  16.  * As much as possible, symbols are patterned after corresponding
  17.  * TOPS-20 symbols, with non-alphameric characters (. and %) replaced
  18.  * by underscores.
  19.  */
  20.  
  21. #ifndef stdin
  22. #include <stdio.h>
  23. #endif
  24. #ifndef _JBLEN
  25. #include <setjmp.h>
  26. #endif
  27. #include "cmfnc.h"        /* get function-specific symbols */
  28. #include "ccmdmd.h"        /* get machine dependent symbols */
  29.  
  30. /*
  31.  * BRKTAB is a pair of 128-bit arrays specifying the break characteristics
  32.  * of the ASCII characters.  The _br1st array specifies characters which
  33.  * will break field input when they are typed as the first character of
  34.  * a field.  The _brrest array specifies characters that break in other
  35.  * than the first position.  Each array contains one bit per ASCII 
  36.  * code, ordered according to the ASCII sequence.  The leftmost (most
  37.  * significant) bit of the first byte corresponds to ASCII code 0, and
  38.  * the rightmost bit of that same byte corresponds to ASCII code 7.
  39.  * Leftmost bit of the second bit is for ASCII code 8, and so on.
  40.  * When a bit is on, the corresponding character will act as a break
  41.  * character, otherwise it will not.
  42.  *
  43.  * Routines in module cmutil can be used to construct and maintain
  44.  * break tables.
  45.  */
  46.  
  47. typedef struct BRKTAB {
  48.     char _br1st[16];    /* Bit array for initial character breaks */
  49.     char _brrest[16];    /* Bit array for subsequent breaks */
  50. } brktab;
  51.  
  52. /*
  53.  * FDB structures hold information required to parse specific fields of
  54.  * a command line.
  55.  */
  56.  
  57. typedef struct FDB {
  58.     int    _cmfnc;        /* Function code for this field */
  59.     int    _cmffl;        /* Function specific parse flags */
  60.     struct FDB * _cmlst;    /* Link to alternate FDB */
  61.     pdat    _cmdat;        /* Function specific parsing data */
  62.     char *    _cmhlp;        /* pointer to help string */
  63.     char *    _cmdef;        /* pointer to default string */
  64.     brktab * _cmbrk;    /* pointer to special break table */
  65. } fdb;
  66.  
  67. /* Common flag defined for all parse functions */
  68. #define    CM_SDH    0x8000        /* Suppress default help message */
  69.  
  70. typedef struct histbuf {
  71.     int *buf;
  72.     int len;
  73. } cmhistbuf;
  74.  
  75.  
  76.  
  77. typedef struct hist {
  78.     cmhistbuf *bufs;        /* array of history buffers */
  79.     int  len;            /* how many buffers there are */
  80.     int  next;            /* index of next buffer to write into */
  81.     int  current;        /* index of current point in history */
  82.     int  enabled;        /* tell if we should remember */
  83. } cmhist;
  84. /*
  85.  * CSB structure holds information on the state of parsing a command
  86.  * line, as well as pointers to required buffers.
  87.  */
  88.  
  89. typedef struct CSB {
  90.     int     _cmflg;        /* flags describing parse state */
  91.     int    _cmflg2;    /* more flags */
  92.     FILE *  _cmij;        /* file for command input */
  93.     FILE *    _cmoj;        /* file for command output */
  94.     FILE *  _cmej;        /* file for error output */
  95.     char *    _cmrty;        /* pointer to prompt string */
  96.     int *    _cmbfp;        /* pointer to beginning of user input */
  97.     int *    _cmptr;        /* pointer to beg of next field to parse */
  98.     int     _cmcnt;        /* # of chars in buffer past _cmptr */
  99.     int    _cminc;        /* number of unparsed chars after _cmptr */
  100.     int *    _cmhst;        /* history parse point */
  101.     char *    _cmabp;        /* pointer to beginning of atom buffer */
  102.     int    _cmabc;        /* size of atom buffer */
  103.     char *    _cmwbp;        /* pointer to beginning of work buffer */
  104.     int    _cmwbc;        /* size of work buffer */
  105.     int (** _cmact)();    /* table of character action routines */
  106.     int     _cmbkc;            /* break character that caused deferred */
  107.                 /*  action or confirmation */
  108.     int    _cmcmx;        /* maximum column position on terminal */
  109.     int    _cmcol;        /* current column position on terminal */
  110.     int    _cmerr;        /* most recent parse error */
  111.     fdb *    _cmifd;        /* ptr to FDB giving an incomplete parse */
  112.     int     (* _cmrph)();    /* function to call when reparse is needed */
  113.     int     (* _cmerh)();    /* function to call on parse error */
  114.     char *  _cmntb;        /* comment to eol string */
  115.     char *    _cmnts;        /* delimited comment beginning */
  116.     char *    _cmnte;        /* delimited comment end */
  117.     int     _cmmax;        /* maximum number of help tokens to display */
  118.     int     (* _cmblh)();    /* function to call nonblocking and no data */
  119.     int     _cmwrp;        /* column to wrap at */
  120.     cmhist *_cmhist;    /* command history  structure */
  121. } csb;
  122.  
  123. /* Flags that can be set in individual character entries (each an int) in
  124. ** the _cmbfp buffer of the CSB.  The CC_QUO flag is the high order bit in
  125. ** the right half, all the rest are in the left half.  CC_QUO is left in
  126. ** the right half so that parse routines can see it, since the parse routines
  127. ** get their data as character strings, without the left half flags.
  128. **/
  129.  
  130. #define    CC_CHR    0x007f        /* character data field */
  131. #define CC_QUO    0x0080        /* character was quoted */
  132. #define    CC_QCH    0x00ff        /* character data with quote flag */
  133. #define    CC_NEC    0x0100        /* character was not echoed */
  134. #define CC_HID    0x0200        /* character is hidden from user */
  135. #define CC_SKP    0x0400        /* character is to be skipped (not */
  136.                 /*  considered input for parsing) */
  137. #define    CC_CSK    0x0800        /* char is conditionally skipped, */
  138.                 /*  meaning that it is skipped as */
  139.                 /*  long as it is followed by a (possibly */
  140.                 /*  empty) string of characters with the */
  141.                 /*  CC_CSK flag, and eventually a character */
  142.                 /*  with the CC_SKP flag. */
  143. #define CC_ACT    0x1000        /* char should be treated as an action char */
  144.                 /*  on reparse. */
  145.  
  146. /* Flag values for _cmflg field of CSB */
  147.  
  148. /*   Settable by user... */
  149. #define    CM_RAI    0x0001        /* Convert to uppercase before parsing */
  150. #define    CM_WKF    0x0002        /* Wake up as each field is terminated */
  151. #define    CM_NEC    0x0004        /* Do not echo tty input as it is typed */
  152.  
  153. /*   Maintained by ccmd routines */
  154. #define CM_ESC    0x0008        /* This field got completion to successful */
  155.                 /*  parse */
  156. #define    CM_NOP    0x0010        /* Field could not be parsed */
  157. #define    CM_RPT    0x0020        /* Reparse needed -- previously parsed */
  158.                 /*  input has been edited */
  159. #define    CM_SWT    0x0040        /* Switch was terminated with a colon */
  160. #define    CM_PFE    0x0080        /* Previous field got completion (for */
  161.                 /*  noise word handling) */
  162. #define    CM_DRT    0x0100        /* New input has been typed (and possibly */
  163.                 /*  erased) since the last cmini call on */
  164.                 /*  this CSB. */
  165. #define CM_CFM    0x0200        /* This field was terminated by a newline */
  166. #define    CM_ACT    0x0400            /* Deferred action is set, waiting for a */
  167.                 /*  field to run out of input */
  168. #define    CM_PRS    0x0800        /* Data has been parsed in this cmd line */
  169.                 /*  (used to ignore confirms following only */
  170.                 /*  white space) */
  171. #define    CM_TTY    0x1000        /* Command source is a terminal */
  172. #define    CM_CRT    0x2000        /* Command source is a video terminal */
  173. #define    CM_NAC    0x4000        /* Do not copy parsed text to atom buffer */
  174. #define CM_CMT    0x8000        /* Currently inside a comment */
  175.  
  176. /*
  177.  * flags bits for the second flag word.
  178.  */
  179.  
  180. /* 
  181.  * user settable bits.
  182.  */
  183. #define CM_NIN    0x0001        /* don't do indirections */
  184.  
  185. /*
  186.  * CCMD maintained bits
  187.  */
  188. #define CM_IND    0x0002        /* currently in an indirect parse */
  189.  
  190. extern csb cmcsb;        /* CSB for all parses (ccmd) */
  191.  
  192. /* Forward declarations for routines that return anything other than int */
  193.  
  194. fdb *fdbchn();
  195.  
  196. /* Miscellaneous definitions */
  197.  
  198. #ifndef TRUE
  199. #define    TRUE    -1
  200. #define    FALSE    0
  201. #endif
  202.  
  203. #ifndef NULL
  204. #define NULL 0
  205. #endif
  206. extern char *cmrealloc();
  207.